<?php

namespace App\Admin\Controllers\Statistics;


use App\Admin\Controllers\AdminController;
use App\Admin\Extensions\Tools\TypeSelect;
use App\Admin\Repositories\Statistics\SaleRepository;
use Dcat\Admin\Admin;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;

class SaleController extends AdminController
{

    public bool $disable_pagination = true;
    public bool $disable_actions = true;
    public bool $create = false;

    public function index(Content $content): Content
    {
        return $content
            ->title(trans('statistics.labels.statisticsSale'))
            ->body($this->grid());
    }

    protected function grid(): Grid
    {
        return Grid::make(new SaleRepository(), function (Grid $grid) {
            $grid->column('date', trans('statistics.fields.date_time'));
            $grid->column('enter', '进线');
            $grid->column('register', '挂号');
            $grid->column('consultation', '看诊');
            $grid->column('deal', '成交');
            $grid->column('money', '成交业绩');
            $grid->column('deal_rate', '成交率');
            $grid->column('register_rate', '挂号率');
            $grid->column('consultation_rate', '看诊率');
            $grid->column('unit_price', '客单');

            $grid->filter(function (Grid\Filter $filter) {
                switch (request('type', 'day')) {
                    case 'day':
                        $filter->equal('date', trans('admin.time'))->month();
                        break;
                    case 'month':
                        $filter->equal('date', trans('admin.time'))->year();
                        break;
                }
            });

            $grid->tools(new TypeSelect());
            $grid->disableCreateButton();
            $this->gridCommon($grid);

            Admin::style(
                <<<STYLE
    .table-responsive {
        overflow-x: initial !important;
    }
    .table-responsive thead th {
        position: sticky;
        top: 0;
        background-color: #f8f9fa;
    }
STYLE

            );
        });
    }
}
